package com.example.salarytotal;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SalaryTotalMapper
                         // k1        v1      k2          v2
        extends Mapper<LongWritable, Text, IntWritable,IntWritable> {

    @Override
    protected void map(LongWritable k1, Text v1, Context context) throws IOException, InterruptedException {

        String  line  = v1.toString();
        //7369,SMITH,CLERK,7902,1980/12/17,800,,20
        //按逗号进行分词：split(“,”)方法
        String[] datas = line.split(",");
        //{"7369","SMITH","CLERK","7902","1980/12/17","800","","20"}
        //map的输出
        IntWritable k2 = new IntWritable();
        //部门编号
        String deptNO = datas[7];
        k2.set(Integer.parseInt(deptNO));
        IntWritable v2 = new IntWritable();
        //薪水
        String salary = datas[5];
        v2.set(Integer.parseInt(salary));
        //输出k2, v2：context.write()方法
        context.write(k2,v2);



    }
}
